const { ipcMain, BrowserWindow } = require("electron");
const WinState = require("electron-win-state").default;
const saveas = require("./saveas");

ipcMain.handle("on-open-event", async (e, url) => {
  const winState = new WinState({
    defaultWidth: 1280,
    defaultHeight: 680,
    electronStoreOptions: {
      name: "window-state-open",
    },
  });
  const win = new BrowserWindow({
    ...winState.winOptions,
  });

  win.loadURL(url);

  win.webContents.on("context-menu", (e, args) => {
    if (args.srcURL) {
      saveas(args.srcURL);
    }
  });

  winState.manage(win);
});
